app.controller('homeCtr',["$scope","$http","$state","fileReader","Upload","systemService",function ($scope,$http,$state,fileReader,Upload,systemService) {
	/**
	 * 获取登录人
	 */
	$http({
		method:'post',
		url:'/home',
	}).then(function(data){
		$scope.aa=data.data.message;
		$scope.imageSrc=data.data.img;
		console.log(data.data);
	})
	/**
	 * 跳到修改
	 */
	$scope.update=function(){
		$state.go("update");
	}
	/**
	 * 预览图片
	 */
	$scope.getFile=function(){
		fileReader.readAsDataUrl($scope.file,$scope).then(function(result){
			$scope.imageSrc=result;
		});
	}
	/**
	 * 上传图片到后台
	 */
	$scope.upload=function(){
        var form = new FormData();
        var file = document.getElementById("image").files[0];
        form.append('file', file);
        systemService.imageup('/update',form, function(res){
			console.info(res.success);
			if (res.success) {
				$scope.imageSrc=res.message;
			}
		},null);
	}
	/**
	 * 上传excel
	 */
	$scope.uploadexcel=function(){
		$("#excel").click();
	}
	$("#excel").on("change",function(){
		var formData=new FormData();
		var file=document.getElementById("excel").files[0];
		if (file.name) {
			var fileName=file.name.substring(file.name.lastIndexOf(".")+1);
			if (fileName=="xlsx"||fileName=="xls") {
				formData.append("file",file);
				systemService.uploadexcel('/uploadexcel',formData,function(res){
					alert(res.message);
					console.log(res);
				},null);
			}else{
				alert("文件格式不正确,请上传以.xlsx,.xls为后缀的文件名");
				$("#excel").val("");
			}
		}
	})
	
}])
//        $http({
//            method: 'POST',
//            url: '/upload',
//            data: form,
//            headers: {'Content-Type': undefined},
//            transformRequest: angular.identity
//        }).success(function (data) {
//            console.log('upload success');
//        }).error(function (data) {
//             console.log('upload fail');
//        })